package com.cqs.learning.spring.cloud.producer.web.controller;

import com.cqs.learning.spring.cloud.producer.service.ConfigService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.AsyncContext;
import javax.servlet.http.HttpServletRequest;

/**
 * 异步处理
 *
 * @author lixw
 * @date created in 13:59 2020/5/4
 */
@RestController
@Log4j2
public class AsyncController {

    @Autowired
    private ConfigService configService;

    /**
     * @param request
     */
    @RequestMapping("/async")
    public void async(HttpServletRequest request) {
        log.info("使用异步处理得方式");
        final AsyncContext asyncContext = request.startAsync();
        configService.asyncReadConfig(asyncContext);
    }

    /**
     * 修改配置文件 并触发事件
     *
     * @return
     */
    @RequestMapping("/pub")
    public String pushEvent() {
        return configService.pushEvent();
    }


}
